function getCookie(name) {
    var r = document.cookie.match("\\b" + name + "=([^;]*)\\b");
    return r ? r[1] : undefined;
}


$(function () {

    $(".focused").click(function () {
        // TODO 取消关注当前新闻作者
        var user_id = $(this).attr('data-userid')
        var params = {
            'user_id': user_id,
            'action': 'unfollow'
        }
        $.ajax({
            url: '/news/followed_user',
            type: 'post',
            data: JSON.stringify(params),
            contentType: 'application/json',
            headers:{'X-CSRFToken':getCookie('csrf_token')},
            success:function (response) {
                if (response.errno == '0'){
                    window.location.reload()
                }else if (response.errno == '4101') {
                    $('.login_form_con').show();
                }else{
                    alert(response.errmsg)
                }
            }

        })
    })
})